#!/sbin/openrc-run
command="/usr/bin/noip2"
command_user="noip:noip"
procname="noip2"

description="no-ip.com Dynamic DNS Update Client"
description_checkconfig="Verify existenace of a configuration file"
description_configure="Generate a configuration file"

extra_commands="checkconfig configure"

depend() {
        use logger dns
        need net
}

checkconfig() {
	if [ ! -f "${CFGFILE}" ] ; then
		eerror "Please create ${CFGFILE} by using the command configure"
		return 1
	fi
	return 0
}

configure() {
	if [ -r "${CFGFILE}" ] ; then
		read -p "Configuration file already exist, overwrite it? [y/N]: " a
		if [[ "$a" != "y" ]] && [[ "$a" != "Y" ]] ; then
			eerror "Aborting"
			return 1
		fi
	fi

	su -mp -s /bin/sh noip -c "$command -C"
}

start_pre() {
	if [ "${RC_CMD}" != "restart" ] ; then
		checkconfig || return $?
	fi
}

stop_pre() {
	if [ "${RC_CMD}" = "restart" ] ; then
		checkconfig || return $?
	fi
}

